<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <title>供品管理</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
    <style>
        body {
            font-size: 14px;
        }

        footer.aui-nav {
            z-index: 99999;
        }

        header.aui-bar {
            background: #fff;
            position: fixed;
        }

        .contain {
        }

        .aui-title {
            color: #000;
        }

        .aui-nav .aui-bar-tab .active .aui-iconfont, .aui-nav .aui-bar-tab .active p {
            color: #327afa !important;
        }

        .active {
            color: #327afa !important;
        }

        .aui-tab-nav li.active {
            color: #327afa;
            border-bottom: 2px #327afa solid;
        }

        .aui-bar .aui-iconfont {
            color: #000;
        }

        .send {
            font-size: 12px !important;
        }

        .aui-img-object {
            width: 60px;
            height: 60px;
            margin-right: 10px;
        }

        .aui-img-body {
            width: 62%;
            float: left;
        }

        .addInfo {
            font-size: 13px;
             margin-top:2px;
        }

        .status {
            /*height: 40px;
            line-height: 40px;*/
        }

        .aui-ellipsis-1 {
            padding: 0;
            margin-bottom: 2px;
        }

        .mui-btn-red {
            background: #ff3333;
        }

        .spanStatus {
            display: block;
            border-radius: 4px;
            padding: 4px;
            height: 20px;
            line-height: 20px;
            box-sizing: content-box;
            margin-top: 8px;
        }

        .receive {
            background: #327afa;
            color: #fff;

        }

        .mui-table-view-cell:after, .mui-table-view:before, .mui-table-view:after {
            height: inherit;
            background-color: transparent;
            left: 0;
        }

        .mui-table-view-cell:after {
            bottom: -100%;
        }

        .mui-table-view-cell:last-child:after, .mui-table-view-cell:last-child:before {
            height: inherit;
        }

        .price {
            display: block;

        }

        .mui-table-view-cell {
            padding: 0;
        }

        .mui-table-view-cell > .mui-slider-handle {
            padding: 10px 15px;
            overflow: hidden;
        }

        .price em {
            color: #ff0005;
            margin-right: 3px;
        }

        .handle {
            width: 100%;
            background: #f3f3f3;
            overflow: hidden;
            padding: 10px 0;
            display: none;
        }

        .handle span {
            display: block;
            width: 33%;
            float: left;
            text-align: center;
        }

        .fold:before {
            content: "\e6de" !important;
        }

        .content2, .content3 {
            display: none;
        }

        .content3 .handle span:first-of-type() {
            visibility: hidden;
        }
    </style>
</head>
<body>
<div class="contain">
    <ul class=" mui-table-view friendList content1" id="supply-content">

    </ul>

</div>
<script id="supply-template" type="text/x-dot-template">
    {{ for (var i in it) { }}
    <li class="mui-table-view-cell mui-media aui-border-b" tapmode id="goods{{=it[i].itemid}}">
        <div class="mui-slider-handle">
            <img class="aui-img-object aui-pull-left" src="{{=it[i].thumb}}" onclick="openInfo('{{=it[i].itemid}}')">

            <div class="aui-img-body" onclick="showHandle(this)">
                <div class="comName aui-ellipsis-1">{{=it[i].title}}</div>
                <p class="aui-ellipsis-1 addInfo"><span class="price"><em>￥{{=it[i].price}}元</em></span></p>
            </div>
            <div class="status aui-pull-right" tapmode onclick="showHandle(this)">
                <span class="aui-iconfont aui-icon-unfold spanStatus"></span>
            </div>
        </div>
        <div class="handle zfBlue">
            {{? it[i].status == 3}}<span data-status="4" data-goodsId="{{=it[i].itemid}}"
                                         onclick="supplyManagementUpdate(this)">下架</span>{{?}}
            {{? it[i].status == 4}}<span data-status="3" data-goodsId="{{=it[i].itemid}}"
                                         onclick="supplyManagementUpdate(this)">上架</span>{{?}}
            <span data-goodsId="{{=it[i].itemid}}" onclick="supplyManagementDelete(this)">删除</span >
            <span  data-goodsId="{{=it[i].itemid}}" onclick="editGoods('{{=it[i].itemid}}')">修改</span>
        </div>
    </li>
    {{ } }}
</script>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/jquery-1.11.3.js"></script>
<script type="text/javascript" src="../../script/mui.js"></script>
<script type="text/javascript" src="../../script/doT.min.js"></script>
<script type="text/javascript">
    var UIInput, inputId, inputValue, page = 1, isLock = false, status = 3;
    apiready = function () {
        api.parseTapmode();
        var header = $api.dom('header');
        UIInput = api.require('UIInput');
        $api.fixIos7Bar(header);


        getStorageAll();
        //接收监听
        api.addEventListener({
            name: 'supplyStatus'
        }, function (ret) {
            if (ret && ret.value) {
                isLock=false;
                page = 1;
                status = ret.value.status
                api.refreshHeaderLoading();
                return false;
            }
        });

        api.setRefreshHeaderInfo({
            visible: true,
            loadingImg: 'widget://image/ptr_pull.png',
            bgColor: '#efeff4',
            textColor: '#959595',
            textDown: '下拉刷新',
            textUp: '松开刷新',
            showTime: true
        }, function (ret, err) {
            isLock=false;
            page = 1;
            supplyManagement(status);
        });
        api.refreshHeaderLoading();

        //监听是否达到底部上拉加载
        api.addEventListener({
            name: 'scrolltobottom'
        }, function (ret, err) {
            page++;
            if (isLock == false) {
                supplyManagement(status);
            }
        })
    }
    // 显示隐藏操作
    function showHandle(obj) {
        if ($(obj).find("span").hasClass("fold")) {
            $(obj).find("span").removeClass("fold");
            $(obj).parents('li').find(".handle").css({"display": "none"})
        } else {
            $(obj).find("span").addClass("fold");
            $(obj).parents('li').find(".handle").css({"display": "block"})
        }
        event.preventDefault();
        event.stopPropagation();
    }

    function openInfo(itemid) {
        api.openWin({
            name : 'proInfo_win',
            url : '../proInfo_win.html',
            pageParam : {
                itemid : itemid
            },
            // delay : 300
        });
    }
    //获取供应列表
    function supplyManagement(status,toPage) {
        if(isLock)return;
        isLock = true;
        toPage=toPage?toPage:page;

        if(toPage==1)api.refreshHeaderLoading();

        data = {
            status: status,
            userName: user_name,
            page: page,
        };
        url = "User/supplyManagement";
        ajaxRequest(url, 'post', data, function (ret, err) {
            isLock = false;
            api.refreshHeaderLoadDone();
            if (ret.status == 1) {
                var content = $api.byId('supply-content');
                var tpl = $api.byId('supply-template').text;
                var tempFn = doT.template(tpl);
                if (page > 1) {
                    if(!$.trim(ret.msg)){
                        isLock=true;
                        return;
                    }
                    $api.append(content, tempFn(ret.msg));
                } else {
                    $api.html(content, tempFn(ret.msg));
                }
            } else {
                if (page == 1) {
                    $("#supply-content").empty();
                }
                api.toast({
                    msg: '已经加载完',
                    duration: 2000,
                    location: 'bottom'
                });
                isLock=true;
            }
        });
    }

    //上下架商品
    function supplyManagementUpdate(obj) {
        var goodsId = $(obj).attr('data-goodsId');
        var status = $(obj).attr('data-status');
        showLoading();
        data = {
            status: status,
            goodsId: goodsId,
            userName: user_name,
        };
        url = "User/supplyManagementUpdate";
        ajaxRequest(url, 'post', data, function (ret, err) {
            hideLoading();
            if (ret.status == 1) {
                $('#goods' + goodsId).hide();
                api.toast({
                    msg: '更新成功',
                    duration: 2000,
                    location: 'bottom'
                });
                //发送监听
                api.sendEvent({
                    name: 'supplyCountUpdate',
                    extra: {
                        key: 'true'
                    }
                });
            } else {
                api.toast({
                    msg: '更新失败',
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });
        event.preventDefault();
        event.stopPropagation();
    }

    //删除商品
    function supplyManagementDelete(obj){
        if(confirm('确定删除吗')){
            var goodsId = $(obj).attr('data-goodsId');
            showLoading();
            data = {
                goodsId: goodsId,
                userName: user_name,
            };
            url = "User/supplyManagementDelete";
            ajaxRequest(url, 'post', data, function (ret, err) {
                hideLoading();
                if (ret.status == 1) {
                    $('#goods' + goodsId).hide();
                    api.toast({
                        msg: '删除成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    //发送监听
                    api.sendEvent({
                        name: 'supplyCountUpdate',
                        extra: {
                            key: 'true'
                        }
                    });
                } else {
                    api.toast({
                        msg: '删除失败',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
            event.preventDefault();
            event.stopPropagation();
        }
    }
    //修改商品
    function editGoods(goodsId) {
        api.openWin({
            name:"goodsInfo",
            url:"releaseEdit_win.html",
            pageParam:{
                goodsId:goodsId
            }
        })
        event.preventDefault();
        event.stopPropagation();
    }
</script>
</html>
